package com.ericsson.mhealth.client.widgets;

import gwt.charting.client.SimpleLineChart;

import com.ericsson.mhealth.client.eventbus.EventBus;
import com.ericsson.mhealth.client.events.OpenWindowEvent;
import com.ericsson.mhealth.client.handlers.OpenWindowHandler;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ResizeComposite;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class MainPanel extends ResizeComposite {
	
	private EventBus eventBus;

	private static MainPanelUiBinder uiBinder = GWT
			.create(MainPanelUiBinder.class);

	interface MainPanelUiBinder extends UiBinder<Widget, MainPanel> {
	}
	
	@UiField(provided=true)
	SimpleLineChart viewer;
	
	@UiField Button button;

	@Inject
	public MainPanel(SimpleLineChart viewer, EventBus eventBus) {
		this.viewer = viewer;
		this.eventBus = eventBus;
		
		this.viewer.setHeight("480");
		this.viewer.addEvent(eventBus, OpenWindowEvent.getType(), new OpenWindowHandler() {

			@Override
			public void onWindowOpen(OpenWindowEvent e) {
				Window.alert("test" + e.toString());				
			}
			
		});
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	@UiHandler("button")
	void handleClick(ClickEvent e) {
		eventBus.fireEvent(new OpenWindowEvent());
	}
}
